<?php

namespace common\modules\wechat\models\backend;

use common\widgets\DateTimePicker;
use common\widgets\grid\CheckboxColumn;
use common\widgets\Form;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\modules\wechat\models\backend\Fans;

/**
 * FansSearch represents the model behind the search form about `common\modules\wechat\models\backend\Fans`.
 */
class FansSearch extends Fans
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'wid', 'status', 'created_at', 'updated_at'], 'integer'],
            [['open_id'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * @return string
     */
    public function classLabelName()
    {
        return Yii::t('backend/wechat', 'Fans List');
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Fans::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if ( ! $this->validate())
        {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id'         => $this->id,
            'wid'        => $this->wid,
            'status'     => $this->status,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'open_id', $this->open_id]);

        return $dataProvider;
    }

    /**
     * 返回字段的定义信息
     *
     * @return array
     */
    public function gridViewColumns()
    {
        return [
            [
                'class' => CheckboxColumn::classname(),
            ],

            [
                'attribute' => 'id',
            ],

            'wid',

            'open_id',

            'status',

            [
                'attribute' => 'created_at',
                'format'    => ['date', 'php:Y-m-d H:i:s'],
                'filter'    => \common\widgets\DateTimePicker::widget([
                    'model'         => $this,
                    'attribute'     => 'created_at',
                    'options'       => [
                        'class' => 'form-control',
                    ],
                    'pluginOptions' => [
                        'dateFormat' => 'dd.mm.yy',
                    ],
                ]),
            ],

            [
                'attribute' => 'updated_at',
                'format'    => ['date', 'php:Y-m-d H:i:s'],
                'filter'    => \common\widgets\DateTimePicker::widget([
                    'model'         => $this,
                    'attribute'     => 'updated_at',
                    'options'       => [
                        'class' => 'form-control',
                    ],
                    'pluginOptions' => [
                        'dateFormat' => 'dd.mm.yy',
                    ],
                ]),
            ],

            [
                'class' => 'common\widgets\grid\ActionColumn',
            ],
        ];
    }
}
